﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SFP;
using SFP.Animation2D;

namespace LevelEditor
{
    public class LayerLE
    {
        private Layer layer;
        private Panel layerPanel;
        private Label layerNameLabel;
        private CheckBox visibleCheckBox;
        private Panel layersPanel;
        private LevelEditorForm levelEditorForm;
        private Dictionary<GameObject, ObjectLE> gameObjObjectLEDict = new Dictionary<GameObject, ObjectLE>();

        public LayerLE(Layer layer, Panel layerPanel, Label layerNameLabel, CheckBox visibleCheckBox, LevelEditorForm levelEditorForm)
        {
            this.layer = layer;
            this.layerPanel = layerPanel;
            this.layerNameLabel = layerNameLabel;
            this.visibleCheckBox = visibleCheckBox;
            this.layersPanel = (Panel)layerPanel.Parent;
            this.levelEditorForm = levelEditorForm;
        }

        public Layer GetLayer()
        {
            return layer;
        }

        public Panel GetLayerPanel()
        {
            return layerPanel;
        }

        public Label GetLayerNameLabel()
        {
            return layerNameLabel;
        }

        public CheckBox GetVisibleCheckBox()
        {
            return visibleCheckBox;
        }

        public Dictionary<GameObject, ObjectLE> GetGameObjObjectLEDict()
        {
            return new Dictionary<GameObject, ObjectLE>(gameObjObjectLEDict);
        }

        public void AddGameObjObjectLELink(GameObject gameObject, ObjectLE objectLE)
        {
            gameObjObjectLEDict.Add(gameObject, objectLE);
        }

        public void RemoveGameObjObjectLELink(GameObject gameObject)
        {
            gameObjObjectLEDict.Remove(gameObject);
        }

        public void layerPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                levelEditorForm.SetActiveLayerLE(this);
        }

        public void layerPanel_MouseDoubleClick(object sender, EventArgs e)
        {
            new LayerPreferencesForm(this, levelEditorForm).ShowDialog();
        }

        public void visibleCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            layer.setVisible(visibleCheckBox.Checked);
            levelEditorForm.SetActiveObjectLE(null);
        }
    }
}
